import Vue from 'vue'
import Vuex from 'vuex'
import { stat } from 'fs';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        token: window.localStorage.getItem('token') == null ? '' : window.localStorage.getItem('token'),
        // 0 未登录、1 学生、2 老师、3 管理员
        status: window.localStorage.getItem('status') == null ? 0 : window.localStorage.getItem('status')
    },
    mutations: {
        setToken(state, payload) {
            window.localStorage.setItem('token', payload.token);
            window.localStorage.setItem('status', Number(payload.status));
            state.token = payload.token;
            state.status = payload.status;
        },
        clearToken(state) {
            window.localStorage.removeItem('token');
            window.localStorage.removeItem('status');
        }
    }
})

export default store;